const arr = [1,2,[3,4,5,[6,7,8],9],10,[11,12]];
//flat
// console.log(arr.flat(Infinity))

//递归
function flat(arr) {
    let res = []
    arr.forEach(element => {
        Array.isArray(element) ? res = res.concat(flat(element)) : res.concat(element)
    });
    return res
}

// console.log(flat(arr))

//reduce
function flat2(arr) {
    return arr.reduce((pre, cur) => {
        return pre.concat(Array.isArray(cur) ? flat2(cur) : cur)
    }, [])
}

// console.log(flat2(arr))

//toString
function flat3() {
    return arr.toString().split(',').map(item => {
        return item - 0
    })
}

console.log(flat3(arr))